package run;

import java.util.StringTokenizer;

class Language
{
	public class MenuNames
	{
		public String settings;
		public String help;
	}
	
	public class SettingsMenu
	{
		public String preferences;
		public String exit;
	}
	
	public class HelpMenu
	{
		public String about;
	}
	
	public class MainGui
	{
		public String search;
		public String downloads;
	}
	
	public class TableColumns
	{
		public String name;
		public String length;
		public String size;
		public String bitrate;
		public String progress;
		public String canceled;
		public String done;
	}
	
	public class SearchListMenu
	{
		public String download;
		public String copyUrl;
	}
	
	public class DownloadsListMenu
	{
		public String cancel;
		public String openFolder;
	}
	
	public class AboutGui
	{
		public String title;
		public String subtitle;
		public String developer;
		public String and;
		public String email;
		public String version;
		public String basedOn;
		public String homepage;
	}
	
	public class SettingsGui
	{
		public String title;
		public String downloadPath;
		public String browse;
		public String language;
		public String minimumBitrate;
		public String lookAndFeel;
		public String restart;
		public String ok;
		public String cancel;
		public String invalidPath;
		public String invalidBitrate;
		public String invalidBitrateRange;
		public String connection;
		public String password;
		public String username;
		public String invalidDataMsg;
	}

	public MenuNames menuNames;
	public SettingsMenu settingsMenu;
	public HelpMenu helpMenu;
	public MainGui mainGui;
	public TableColumns tableColumns;
	public SearchListMenu searchListMenu;
	public DownloadsListMenu downloadsListMenu;
	public AboutGui aboutGui;
	public SettingsGui settingsGui;
	
	public Language()
	{
		menuNames = new MenuNames();
		settingsMenu = new SettingsMenu();
		helpMenu = new HelpMenu();
		mainGui = new MainGui();
		tableColumns = new TableColumns();
		searchListMenu = new SearchListMenu();
		downloadsListMenu = new DownloadsListMenu();
		aboutGui = new AboutGui();
		settingsGui = new SettingsGui();
	}
	
}

public class LanguageFile
{
	public Language language;
	private String name;
	
	public LanguageFile(String path)
	{
		language = new Language();
		
		TextFileStream file = new TextFileStream(path);
		String lines = file.getLines().trim();
		
		StringTokenizer stMain = new StringTokenizer(lines, "]");
		
		while (stMain.hasMoreTokens())
		{
			String token1 = stMain.nextToken().trim();
			if (token1.startsWith("["))
				token1 = token1.substring(1, token1.length());
			StringTokenizer st2 = new StringTokenizer(token1, ";");
			String categoryName = st2.nextToken().trim().toLowerCase();
			while (st2.hasMoreTokens())
			{
				String token2 = st2.nextToken().trim();
				String[] split = token2.split("=");
				String name = split[0].trim();
				String value = split[1].trim();
				if (categoryName.equals("lang_name"))
				{
					if (name.equals("str"))
						this.name = value;
				}
				else if (categoryName.equals("menu_names"))
				{
					if (name.equals("settingsMenuName"))
						language.menuNames.settings = value;
					else if (name.equals("helpMenuName"))
						language.menuNames.help = value;
				}
				else if (categoryName.equals("settings_menu_content"))
				{
					if (name.equals("preferencesName"))
						language.settingsMenu.preferences = value;
					else if (name.equals("exitName"))
						language.settingsMenu.exit = value;
				}
				else if (categoryName.equals("help_menu_content"))
				{
					if (name.equals("aboutName"))
						language.helpMenu.about = value;
				}
				else if (categoryName.equals("main_gui_components"))
				{
					if (name.equals("searchName"))
						language.mainGui.search = value;
					else if (name.equals("downloadsName"))
						language.mainGui.downloads = value;
				}
				else if (categoryName.equals("table_columns"))
				{
					if (name.equals("nameColumn"))
						language.tableColumns.name = value;
					else if (name.equals("lengthColumn"))
						language.tableColumns.length = value;
					else if (name.equals("bitrateColumn"))
						language.tableColumns.bitrate = value;
					else if (name.equals("progressColumn"))
						language.tableColumns.progress = value;
					else if (name.equals("doneStatusText"))
						language.tableColumns.done = value;
					else if (name.equals("canceledStatusText"))
						language.tableColumns.canceled = value;
					else if (name.equals("sizeColumn"))
						language.tableColumns.size = value;
				}
				else if (categoryName.equals("search_list_menu"))
				{
					if (name.equals("downloadMenuName"))
						language.searchListMenu.download = value;
					else if (name.equals("copyUrlMenuName"))
						language.searchListMenu.copyUrl = value;
				}
				else if (categoryName.equals("downloads_list_menu"))
				{
					if (name.equals("cancelMenuName"))
						language.downloadsListMenu.cancel = value;
					else if (name.equals("openFolderMenuName"))
						language.downloadsListMenu.openFolder = value;
				}
				else if (categoryName.equals("about_gui_elements"))
				{
					if (name.equals("titleText"))
						language.aboutGui.title = value;
					else if (name.equals("subTitleText"))
						language.aboutGui.subtitle = value;
					else if (name.equals("developerText"))
						language.aboutGui.developer = value;
					else if (name.equals("emailText"))
						language.aboutGui.email = value;
					else if (name.equals("versionText"))
						language.aboutGui.version = value;
					else if (name.equals("basedOnText"))
						language.aboutGui.basedOn = value;
					else if (name.equals("homepageText"))
						language.aboutGui.homepage = value;
					else if (name.equals("andText"))
						language.aboutGui.and = value;
				}
				else if (categoryName.equals("settings_gui_elements"))
				{
					if (name.equals("titleText"))
						language.settingsGui.title = value;
					else if (name.equals("downloadPathText"))
						language.settingsGui.downloadPath = value;
					else if (name.equals("browseText"))
						language.settingsGui.browse = value;
					else if (name.equals("languageText"))
						language.settingsGui.language = value;
					else if (name.equals("minBitrateText"))
						language.settingsGui.minimumBitrate = value;
					else if (name.equals("lookAndFeelText"))
						language.settingsGui.lookAndFeel = value;
					else if (name.equals("restartText"))
						language.settingsGui.restart = value;
					else if (name.equals("okText"))
						language.settingsGui.ok = value;
					else if (name.equals("cancelText"))
						language.settingsGui.cancel = value;
					else if (name.equals("invalidPathMessage"))
						language.settingsGui.invalidPath = value;
					else if (name.equals("invalidBitrateMessage"))
						language.settingsGui.invalidBitrate = value;
					else if (name.equals("bitrateOutOfRangeMessage"))
						language.settingsGui.invalidBitrateRange = value;
					else if (name.equals("connectionText"))
						language.settingsGui.connection = value;
					else if (name.equals("passwordText"))
						language.settingsGui.password = value;
					else if (name.equals("usernameText"))
						language.settingsGui.username = value;
					else if (name.equals("invalidUsernameAndPasswordMessage"))
						language.settingsGui.invalidDataMsg = value;
				}
			}
		}
	}
	
	public String getName()
	{
		return name;
	}
}
